import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class StateValueBuilderView extends StatelessWidget {
  StateValueBuilderView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("ValueBuilder"),
      ),
      body: Column(
        children: [
          Center(
            child: ValueBuilder<int?>(
              initialValue: 10,
              builder: (value, updateFn) {
                return Column(
                  children: [
                    Text("count ->${value.toString()}" ),
                    ElevatedButton(
                        onPressed: (){
                          updateFn(value! + 1);
                        },
                        child: const Text("valueBuilder -> add")
                    )
                  ],
                );
              },
              onUpdate: (value) {
                if (kDebugMode) {
                  print("Value updated:$value");
                }
              },
              onDispose: () {
                if (kDebugMode) {
                  print("Widget unmounted");
                }
              },
            ),
          )
        ],
      ),
    );
  }
}
